//
// Created by wwl on 2021/12/10.
//
#include <stdio.h>
#include <stdlib.h>

#define LEN sizeof(struct Student)
struct Student {
    long num;
    float score;
    struct Student *next;
};
int n;                           //n为全局变量，本文件模块中各函数均可使用它

struct Student *creat() {       //定义函数。此函数返回一个指向链表头的指针
    struct Student *head;
    struct Student *p1, *p2;
    n = 0;
    p1 = p2 = (struct Student *) malloc(LEN);   //开辟一个新单元
    scanf("%ld,%f", &p1->num, &p1->score);      //输入第1个学生的学号和成绩
    head = NULL;
    while (p1->num != 0) {
        n = n + 1;
        if (n == 1) {
            head = p1;
        } else {
            p2->next = p1;
        }
        p2 = p1;
        p1 = (struct Student *) malloc(LEN);    //开辟动态存储区，把起始地址赋给p1
        scanf("%ld,%f", &p1->num, &p1->score);//输入其他学生的学号和成绩
//        printf("%ld,%ld",&p1->num, &p1->score);
    }
    p2->next = NULL;
    return (head);
}

void print(struct Student *head){
    struct Student *p;
    printf("\nNow,These %d records are :\n",n);
    p = head;
    if(head != NULL){
        do {
            printf("%ld %5.1f\n",p->num,p->score);
            p=p->next;
        } while (p!=NULL);
    }
}
void test() {
    struct Student *pt;
    pt = creat();                   //函数返回链表第一个结点的地址
//    printf("\nnum:%ld\nscore:%5.1f\n", pt->num, pt->score);    //输出第一个结点的成员值
    print(pt);
}
//int simple() {
//
//    struct Student a, b, c, *head, *p;
//    a.num = 10101;
//    a.score = 89.5;
//    b.num = 10103;
//    b.score = 90;
//    c.num = 10107;
//    c.score = 85;
//    head = &a;      //将结点a的起始地址赋给头指针head
//    a.next = &b;     //将结点b的起始地址赋给a结点的next成员
//    b.next = &c;    //将结点c的起始地址赋给b结点的next成员
//    c.next = NULL;  //c结点的next成员g不存放其他地址
//    p = head;       //使p指向a结点
//    do {
//        printf("%ld %5.lf\n", p->num, p->score); //输出p指向的结点数据
//        p = p->next;                                 //使p指向下一结点
//    } while (p != NULL);
//}
/**
 *
 *
 */
